﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionePolveriLib.BL;
using GestionePolveriLib.Facades;

namespace GestionePolveri2.Editors
{
    public partial class LottoNCDettaglio : UserControl
    {
        private LottoNCInfo m_LottoNCInfo = new LottoNCInfo();

        public LottoNCInfo LottoNCInfo
        {
            get
            {
                System.Security.Principal.IPrincipal m_operatore = System.Threading.Thread.CurrentPrincipal;
                OperatoriFacade of = new OperatoriFacade();
                Operatore op = of.GetOperatore(m_operatore.Identity.Name);

                if (m_LottoNCInfo == null) m_LottoNCInfo = new GestionePolveriLib.BL.LottoNCInfo();
                m_LottoNCInfo.IDOperatore = op.ID;
                m_LottoNCInfo.IsLottoBloccato = this.rbLottoBloccato.Checked;
                m_LottoNCInfo.IsLottoNC = this.rbLottoNC.Checked;
                m_LottoNCInfo.Note = this.txtNote.Text;

                if (rbConforme.Checked)
                {
                    m_LottoNCInfo.IsLottoBloccato = false;
                    m_LottoNCInfo.IsLottoNC = false;
                }

                return m_LottoNCInfo;
            }

            set 
            { 
                m_LottoNCInfo = value;

                if (m_LottoNCInfo != null)
                {
                    this.rbLottoBloccato.Checked = m_LottoNCInfo.IsLottoBloccato.GetValueOrDefault();
                    this.rbLottoNC.Checked = m_LottoNCInfo.IsLottoNC.GetValueOrDefault();
                    this.txtNote.Text = m_LottoNCInfo.Note;

                    if (!m_LottoNCInfo.IsLottoNC.GetValueOrDefault() && !m_LottoNCInfo.IsLottoBloccato.GetValueOrDefault())
                    {
                        this.rbConforme.Checked = true;
                    }
                }
                else
                {
                    this.rbConforme.Checked = true;
                }
            }
        }

        public LottoNCDettaglio()
        {
            InitializeComponent();

            //m_LottoNCInfo = new LottoNCInfo();
        }

        public bool Save()
        {
            bool retValue = false;

            LottoNCFacade lncf = new LottoNCFacade();
            
            retValue = lncf.AddOrModify(this.LottoNCInfo);

            return retValue;
        }
    }
}
